# -*- coding: UTF-8 -*-
__author__ = 'Jinkey'
import numpy as np
import sklearn
from sklearn import neighbors
from sklearn.cross_validation import KFold


# ====================快速入门=====================================
print '=' * 35 + '快速入门' + '=' * 25
# 取得knn分类器
knn = neighbors.KNeighborsClassifier()
# data对应着打斗次数和接吻次数
dict = [[3, 104], [2, 100], [1, 81], [101, 10], [99, 5], [98, 2]]
data = np.array(dict)
# labels则是对应Romance和Action
labels = np.array([1, 1, 1, 2, 2, 2])
print labels
# 导入数据进行训练
knn.fit(data, labels)
print knn.predict([1, 90])
# 交叉验证
scores = []
cv = KFold(n=6, n_folds=3, indices=True)
for train, test in cv:
    data_train, labels_train = data[train], labels[train]
    data_test, labels_test = data[test], labels[test]
    scores.append(knn.score(data_test, labels_test))
print(u'平均得分=%.3f\t标准差=%.3f') % (np.mean(scores), np.std(scores))